package com.hanxiaozhang.redis.util;

import com.hanxiaozhang.constant.CacheName;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 〈一句话功能简述〉<br>
 * 〈缓存工具类〉
 *
 * @author hanxinghua
 * @create 2021/4/12
 * @since 1.0.0
 */
@Slf4j
@Component
public class CacheUtil {


    @Autowired
    private RedisUtil redisBaseUtil;

    /**
     * 删除数据字典
     *
     * @param types
     */
    public void delDictByTypes(String[] types) {
        if (types.length < 1) {
            return;
        }
        for (String type : types) {
            redisBaseUtil.delete(CacheName.DICT_12HOUR + "::" + type);
        }
    }


    /**
     * 删除路由和当前用户
     *
     * @param userIds
     */
    public void delRouterAndCurUserByUserIds(Long[] userIds) {
        if (userIds.length < 1) {
            return;
        }
        for (Long userId : userIds) {
            delRouterAndCurUserByUserId(userId);
        }
    }

    /**
     * 删除路由和当前用户
     *
     * @param userId
     */
    public void delRouterAndCurUserByUserId(Long userId) {

        redisBaseUtil.delete(CacheName.ROUTE_BY_USER_ID_2HOUR + "::" + userId);
        redisBaseUtil.delete(CacheName.CURRENT_USER_BY_USER_ID_2HOUR + "::" + userId);
    }


}
